home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
absval.zip
/
ABSVAL.C
next >
Wrap
Text File
|
1993-04-13
|
25KB
|
691 lines
/* ******************************************************************
* Function name : d_absolute(value) / f_absolute(value) /
* i_absolute(value)
*
* Description : This function returns the absolute value of
* the number contained in variable "value"
*
* Variables : value - The number passed to the function
* and modified to contain the absolute
* value
*
* Example : output = d_absolute(10); returns the value 10
* output = f_absolute(-5); returns the value 5
* output = i_absolute(45); returns the value 45
*
* Rules : The function must be passed a numerically defined
* variable. Additionally, the calling program must
* define the "absolute" function in a manner
* consistent with the version of the function called.
* For example if you call d_absolute than the calling
* program must define "d_absolute()" as a "double".
*
* Calling ex. : For d_absolute - double d_absolute(), output, input;
* output = d_absolute(input);
*
* For f_absolute - float f_absolute(), output, input;
* output = f_absolute(input);
*
* For i_absolute - int i_absolute(), output, input;
* output = i_absolute(input);
*
*/
double d_absolute(value)
double value;
{ if ( value < 0 ) return( 0 - value ); else return(value);
}
float f_absolute(value)
float value;
{ if ( value < 0 ) return( 0 - value ); else return(value);
}
i_absolute(value)
int value;
{ if ( value < 0 ) return( 0 - value ); else return(value);
}
/* ******************************************************************
* Function name : d_average(a,b) / f_average(a,b) /
* i_average(a,b)
*
* Description : This function returns the average valuσs of
* the numbers contained in variables "a" and "b"
*
* Variables : a,b - The numbers passed to the function
* are averaged, this average is passed
* back to the calling function
*
* Example : output = d_average(10,20); returns the value 15
* output = f_average(2,4); returns the value 3
* output = i_average(4,5); returns the value 4.5
*
* Rules : The function must be passed a numerically defined
* variable. Additionally, the calling program must
* define the "average" function in a manner
* consistent with the version of the function called.
* For example if you call d_average than the calling
* program must define "d_average()" as a "double".
*
* Calling ex. : For d_average - double d_average();
* double output, input1,input2;
* output = d_average(input1,input2);
*
* For f_average - float f_average();
* float output, input1, input2;
* output = f_average(input1,input2);
*
* For i_average - int i_average();
* float output, input1, input2;
* output = i_average(input1, input2);
*
*/
double d_average(value1,value2)
double value1, value2;
{ return( (value1 + value2) / 2 );
}
float f_average(value1,value2)
float value1, value2;
{ return( (value1 + value2) / 2 );
}
i_average(value1,value2)
int value1, value2;
{ return( (value1 + value2) / 2 );
}
/* ******************************************************************
* Function name : d_cube(value) / f_cube(value) / i_cube(value)
*
* Description : This function returns the cube value of
* the number contained in variable "value"
*
* Variables : value - The number passed to the function
* and modified to contain the cube
* value
*
* Example : output = d_cube(2); returns the value 8
* output = f_cube(3); returns the value 27
* output = i_cube(4); returns the value 64
*
* Rules : The function must be passed a numerically defined
* variable. Additionally, the calling program must
* define the "cube" function in a manner
* consistent with the version of the function called.
* For example if you call d_cube than the calling
* program must define "d_cube()" as a "double".
*
* Calling ex. : For d_cube - double d_cube(), output, input;
* output = d_cube(input);
*
* For f_cube - float f_cube(), output, input;
* output = f_cube(input);
*
* For i_cube - int i_cube(), output, input;
* output = i_cube(input);
*
*/
double d_cube(value)
double value;
{ return( value * value * value );
}
float f_cube(value)
float value;
{ return( value * value * value );
}
i_cube(value)
int value;
{ return( value * value * value );
}
/* ******************************************************************
* Function name : d_to_h(value)
*
* Description : This function converts the number passed
* from a decimal number to a hexadecimal number
*
* Variables : dec - The number passed to the function
* that is converted to hexadecimal
*
* hex - The variable that contains the calculated
* hexadecimal value passed back in the
* return statement
*
* count - this variable is a counter used in the
* "for" loop
*
* Example : output = d_to_h(20); returns the value 24
* output = d_to_h(29); returns the value 1D
* output = d_to_h(42); returns the value 2A
*
* Rules : The function must be passed a variable defined
* as an integer.
*
* Calling ex. : int output, output;
* output = d_to_h(input);
*
*
*/
d_to_h(dec)
int dec;
{ int hex = 0;
int count;
for ( count=0; (dec / 16.0) != 0; count++ )
{ hex = hex + ( dec % 16 ) * i_to_power(10.0, count);
dec = dec / 16;
}
return(hex);
}
/* ******************************************************************
* Function name : is_bin(value)
*
* Description : This function returns a "1" if the value passed
* is a binary digit, mainly a "0" or "1". If the
* value is not a binary digit than a "0" is returned
*
* Variables : value - The number passed to the function
* that is tested as a binary digit
*
* Example : output = is_bin(0); returns the value 1
* output = is_bin(1); returns the value 1
* output = is_bin(2); returns the value 0
*
* Rules : The function must be passed a variable defined
* as a character.
*
* Calling ex. : For is_binary - int output;
* char input[2];
* output = is_binary(input);
*
*
*/
is_bin(value)
char value[];
{ if ( value[0] == '0' || value[0] == '1' ) return(1); else return(0);
}
/* ******************************************************************
* Function name : is_even(value)
*
* Description : This function returns a "1" if the value passed
* is a even. If the value is not
* an even number than a "0" is returned
*
* Variables : value - The number passed to the function
* that is tested as a even number
*
* Example : output = is_even(10); returns the value 1
* output = is_even(11); returns the value 0
* output = is_even(12); returns the value 1
*
* Rules : The function must be passed a variable defined
* as an integer.
*
* Calling ex. : int output, input;
* output = i_is_even(input);
*
*/
is_even(value)
int value;
{ if ( remainder(value,2) == 0 ) return(1); else return(0);
}
/* ******************************************************************
* Function name : is_hex(value)
*
* Description : This function returns a "1" if the value passed
* is a binary digit, mainly a "0" or "1". If the
* value is not a binary digit than a "0" is returned
*
* Variables : value - The number passed to the function
* that is tested as a binary digit
*
* Example : output = is_hex(0); returns the value 1
* output = is_hex(1); returns the value 1
* output = is_hex(2); returns the value 0
*
* Rules : The function must be passed a variable defined
* as a character.
*
* Calling ex. : For is_hex - int output;
* char input[2];
* output = is_hexary(input);
*
*
*/
is_hex(value)
int value;
{ if ( ( value >= '0' && value <= '9' ) ||
( value >= 'A' && value <= 'F' ) ||
( value <= 'a' && value <= 'f' ) )
return(1);
else return(0);
}
/* ******************************************************************
* Function name : is_octal(value)
*
* Description : This function returns a "1" if the value passed
* is an octal digit, mainly a 0 thru 7. If the
* value is not an octal digit than a "0" is returned
*
* Variables : value - The number passed to the function
* that is tested as an octal digit
*
* Example : output = is_octal(0); returns the value 1
* output = is_octal(6); returns the value 1
* output = is_octal(9); returns the value 0
*
* Rules : The function must be passed a variable defined
* as a character.
*
* Calling ex. : For is_octal - int output;
* char input[2];
* output = is_octal(input);
*
*
*/
is_octal(value)
int value;
{ if ( value >= '0' && value <= '7' ) return(1); else return(0);
}
/* ******************************************************************
* Function name : is_odd(value)
*
* Description : This function returns a "1" if the value passed
* is a odd. If the value is not
* an odd number than a "0" is returned
*
* Variables : value - The number passed to the function
* that is tested as a odd number
*
* Example : output = is_odd(10); returns the value 1
* output = is_odd(11); returns the value 0
* output = is_odd(12); returns the value 1
*
* Rules : The function must be passed a variable defined
* as an integer.
*
* Calling ex. : int output, input;
* output = i_is_odd(input);
*
*/
is_odd(value)
int value;
{ if ( remainder(value,2) != 0 ) return(1); else return(0);
}
/* ******************************************************************
* Function name : d_max(value1, value2) / f_max(value1, value2) /
* i_max(value1, value2)
*
* Description : This function returns the number with the maximum
* value.
*
* Variables : value1 - The numbers passed to the function
* value2 and compared to assess the maximum
* value
*
* Example : output = d_max(10); returns the value 10
* output = f_max(-5); returns the value 5
* output = i_max(45); returns the value 45
*
* Rules : The function must be passed a numerically defined
* variable. Additionally, the calling program must
* define the "max" function in a manner
* consistent with the version of the function called.
* For example if you call d_max than the calling
* program must define "d_max()" as a "double".
*
* Calling ex. : For d_max - double d_max(), output, input;
* output = d_max(input);
*
* For f_max - float f_max(), output, input;
* output = f_max(input);
*
* For i_max - int i_max(), output, input;
* output = i_max(input);
*
*/
double d_max(value1, value2)
double value1, value2;
{ if ( value1 > value2 ) return( value1 ); else return(value2);
}
float f_max(value1, value2)
float value1, value2;
{ if ( value1 > value2 ) return( value1 ); else return(value2);
}
i_max(value1, value2)
int value1, value2;
{ if ( value1 > value2 ) return( value1 ); else return(value2);
}
/* ******************************************************************
* Function name : d_min(value1, value2) / f_min(value1, value2) /
* i_min(value1, value2)
*
* Description : This function return≤ thσ number with the minimum
* value.
*
* Variables : value1 - The numbers passed to the function
* value2 and compared to assess the minimum
* value
*
* Example : output = d_min(10); returns the value 10
* output = f_min(-5); returns the value 5
* output = i_min(45); returns the value 45
*
* Rules : The function must be passed a numerically defined
* variable. Additionally, the calling program must
* define the "min" function in a manner
* consistent with the version of the function called.
* For example if you call d_min than the calling
* program must define "d_min()" as a "double".
*
* Calling ex. : For d_min - double d_min(), output, input;
* output = d_min(input);
*
* For f_min - float f_min(), output, input;
* output = f_min(input);
*
* For i_min - int i_min(), output, input;
* output = i_min(input);
*
*/
double d_min(value1, value2)
double value1, value2;
{ if ( value1 < value2 ) return( value1 ); else return(value2);
}
float f_min(value1, value2)
float value1, value2;
{ if ( value1 < value2 ) return( value1 ); else return(value2);
}
i_min(value1, value2)
int value1, value2;
{ if ( value1 < value2 ) return( value1 ); else return(value2);
}
/* ******************************************************************
* Function name : d_percent(value1, value2) / f_percent(value1, value2) /
* i_percent(value1, value2)
*
* Description : This function return≤ thσ number with the minimum
* value.
*
* Variables : value1 - The numbers passed to the function
* value2 and compared to assess the minimum
* value
*
* Example : output = d_percent(10); returns the value 10
* output = f_percent(-5); returns the value 5
* output = i_percent(45); returns the value 45
*
* Rules : The function must be passed a numerically defined
* variable. Additionally, the calling program must
* define the "min" function in a manner
* consistent with the version of the function called.
* For example if you call d_percent than the calling
* program must define "d_percent()" as a "double".
*
* Calling ex. : For d_percent - double d_percent(), output, input;
* output = d_percent(input);
*
* For f_percent - float f_percent(), output, input;
* output = f_percent(input);
*
* For i_percent - int i_percent(), output, input;
* output = i_percent(input);
*
*/
double d_percent(value1, value2)
double value1, value2;
{ return (value1 / value2 );
}
float f_percent(value1, value2)
float value1, value2;
{ return (value1 / value2 );
}
i_percent(value1, value2)
int value1, value2;
{ return (value1 / value2 );
}
/* ******************************************************************
* Function name : d_power(value1, value2) / f_power(value1, value2) /
* i_power(value1, value2)
*
* Description : This function returns the number with the minimum
* value.
*
* Variables : value1 - The numbers passed to the function
* value2 and compared to assess the minimum
* value
*
* Example : output = d_power(10); returns the value 10
* output = f_power(-5); returns the value 5
* output = i_power(45); returns the value 45
*
* Rules : The function must be passed a numerically defined
* variable. Additionally, the calling program must
* define the "min" function in a manner
* consistent with the version of the function called.
* For example if you call d_power than the calling
* program must define "d_power()" as a "double".
*
* Calling ex. : For d_power - double d_power(), output, input;
* output = d_power(input);
*
* For f_power - float f_power(), output, input;
* output = f_power(input);
*
* For i_power - int i_power(), output, input;
* output = i_power(input);
*
*/
double d_to_power(value,n)
double value,n;
{ int count;
double result;
result = 1;
for ( count=1; count <= n; count++ )
result = result * value;
return(result);
}
float f_to_power(value,n)
float value,n;
{ int count;
float result;
result = 1;
for ( count=1; count <= n; count++ )
result = result * value;
return(result);
}
i_to_power(value,n)
int value,n;
{ int count, result;
result = 1;
for ( count=1; count <= n; count++ )
result = result * value;
return(result);
}
/* ******************************************************************
* Function name : is_remainder(value1, value2 )
*
* Description : This function returns a "1" if the value passed
* is a remainder. If the value is not
* an remainder number than a "0" is returned
*
* Variables : value - The number passed to the function
* that is tested as a remainder number
*
* Example : output = is_remainder(10); returns the value 1
* output = is_remainder(11); returns the value 0
* output = is_remainder(12); returns the value 1
*
* Rules : The function must be passed a variable defined
* as an integer.
*
* Calling ex. : int output, input;
* output = i_is_remainder(input);
*
*/
remainder(value1, value2)
int value1, value2;
{ int remaind;
remaind = value1 % value2;
return (remaind);
}
/* ******************************************************************
* Function name : d_round(value) / f_round(value)
*
* Description : This function returns the round value of
* the number contained in variable "value"
*
* Variables : value - The number passed to the function
* and modified to contain the round
* value
*
* Example : output = d_round(2); returns the value 8
* output = f_round(3); returns the value 27
*
* Rules : The function must be passed a numerically defined
* variable. Additionally, the calling program must
* define the "round" function in a manner
* consistent with the version of the function called.
* For example if you call d_round than the calling
* program must define "d_round()" as a "double".
*
* Calling ex. : For d_round - double d_round(), output, input;
* output = d_round(input);
*
* For f_round - float f_round(), output, input;
* output = f_round(input);
*
*/
double d_round(value)
double value;
{ int temp1;
double temp2;
temp1 = value + .5;
temp2 = temp1;
return( temp2);
}
float f_round(value)
float value;
{ int temp1;
float temp2;
temp1 = value + .5;
temp2 = temp1;
return( temp2);
}
/* ******************************************************************
* Function name : d_sqare(value) / f_sqare(value) / i_sqare(value)
*
* Description : This function returns the sqare value of
* the number contained in variable "value"
*
* Variables : value - The number passed to the function
* and modified to contain the sqare
* value
*
* Example : output = d_sqare(2); returns the value 8
* output = f_sqare(3); returns the value 27
* output = i_sqare(4); returns the value 64
*
* Rules : The function must be passed a numerically defined
* variable. Additionally, the calling program must
* define the "sqare" function in a manner
* consistent with the version of the function called.
* For example if you call d_sqare than the calling
* program must define "d_sqare()" as a "double".
*
* Calling ex. : For d_sqare - double d_sqare(), output, input;
* output = d_sqare(input);
*
* For f_sqare - float f_sqare(), output, input;
* output = f_sqare(input);
*
* For i_sqare - int i_sqare(), output, input;
* output = i_sqare(input);
*
*/
double d_sqare(value)
double value;
{ return( value * value );
}
float f_sqare(value)
float value;
{ return( value * value );
}
i_sqare(value)
int value;
{ return( value * value );
}
/* ******************************************************************
* Function name : d_truncate(value) / f_truncate(value)
*
* Description : This function returns the truncate valuσ of
* the number contained in variable "value"
*
* Variables : value - The number passed to the function
* and modified to contain the truncate
* value
*
* Example : output = d_truncate(2); returns the value 8
* output = f_truncate(3); returns the value 27
*
* Rules : The function must be passed a numerically defined
* variable. Additionally, the calling program must
* define the "truncate" function in a manner
* consistent with the version of the function called.
* For example if you call d_truncate than the calling
* program must define "d_truncate()" as a "double".
*
* Calling ex. : For d_truncate - double d_truncate(), output, input;
* output = d_truncate(input);
*
* For f_truncate - float f_truncate(), output, input;
* output = f_truncate(input);
*
*/
double d_truncate(value)
double value;
{ int temp1;
double temp2;
temp1 = value;
temp2 = temp1;
return( temp2);
}
float f_truncate(value)
float value;
{ int temp1;
float temp2;
temp1 = value;
temp2 = temp1;
return( temp2);
}